package com.tju.ocean_ecology_website.service.impl;

import com.tju.ocean_ecology_website.entity.VolunteerInfo;
import com.tju.ocean_ecology_website.dao.VolunteerInfoDao;
import com.tju.ocean_ecology_website.service.VolunteerInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 志愿者信息表(VolunteerInfo)表服务实现类
 *
 * @author shaolong
 * @since 2025-04-29 19:34:46
 */
@Service("volunteerInfoService")
public class VolunteerInfoServiceImpl implements VolunteerInfoService {
    @Resource
    private VolunteerInfoDao volunteerInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public VolunteerInfo queryById(Long id) {
        return this.volunteerInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param volunteerInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<VolunteerInfo> queryByPage(VolunteerInfo volunteerInfo, PageRequest pageRequest) {
        long total = this.volunteerInfoDao.count(volunteerInfo);
        return new PageImpl<>(this.volunteerInfoDao.queryAllByLimit(volunteerInfo, pageRequest), pageRequest, total);
    }

    /**
     * 查询指定行数据
     *
     * @param volunteerInfo 查询条件
     * @param pageRequest 分页对象
     * @return 对象列表
     */
    @Override
    public List<VolunteerInfo> queryAllByLimit(VolunteerInfo volunteerInfo, PageRequest pageRequest) {
        return this.volunteerInfoDao.queryAllByLimit(volunteerInfo, pageRequest);
    }

    /**
     * 新增数据
     *
     * @param volunteerInfo 实例对象
     * @return 实例对象
     */
    @Override
    public VolunteerInfo insert(VolunteerInfo volunteerInfo) {
        this.volunteerInfoDao.insert(volunteerInfo);
        return volunteerInfo;
    }

    /**
     * 修改数据
     *
     * @param volunteerInfo 实例对象
     * @return 实例对象
     */
    @Override
    public VolunteerInfo update(VolunteerInfo volunteerInfo) {
        this.volunteerInfoDao.update(volunteerInfo);
        return this.queryById(volunteerInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.volunteerInfoDao.deleteById(id) > 0;
    }
}
